/**
 *	The NeuroCoSA Toolkit
 *	Copyright (C) 2003-6 Stuart Meikle.
 *
 *	This is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU Lesser General Public
 *	License as published by the Free Software Foundation; either
 *	version 2.1 of the License, or (at your option) any later version.
 *
 *	This library is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *	Lesser General Public License for more details.
 *
 * @author	Stuart Meikle
 * @version	2006-halloween(mk2)
 * @license	LGPL
 */
package org.stumeikle.NeuroCoSA;
import java.io.*;
import java.util.*;
import org.stumeikle.NeuroCoSA.PubSub.InfoService;
import org.stumeikle.NeuroCoSA.PubSub.Publication;
import org.stumeikle.NeuroCoSA.PubSub.Subscriber;
import org.stumeikle.NeuroCoSA.NIS.*;

/** the information store with neurocosa type supported
 *  describes lobes and update sequence
 *  contains the system clock. guess we can generify this later 
 */
public	class	NeuroCoSAInfoService extends InfoService
{
    //static entries to the information service
    
    public NeuroCoSAInfoService()
    {
    }

    public long subscribeTo( String name, Subscriber s )
    {
	//find a publication which matches name and subscribe
	ListIterator	i = getPublications().listIterator();
	for(;i.hasNext();)
	{
	    Info	 p = (Info) i.next();

	    if (p.getName()!=null)
	    {
		if (p.getName().compareTo( name ) == 0)
		{
		    return p.subscribe(s);
		}
	    }
	}

	return -1;
    }

    public InfoString	findInfoString( String name )
    {
	//find a publication which matches name and subscribe
	ListIterator	i = getPublications().listIterator();
	for(;i.hasNext();)
	{
	    Info	 p = (Info) i.next();

	    if (p.getName()!=null)
	    {
		if (p.getName().compareTo( name ) == 0)
		{
		    return (InfoString)p;
		}
	    }
	}

	return null; //or throw an exception, as you like...
    }

    public Info		findInfo( String name )
    {
	//find a publication which matches name and subscribe
	ListIterator	i = getPublications().listIterator();
	for(;i.hasNext();)
	{
	    Info	 p = (Info) i.next();

	    if (p.getName()!=null)
	    {
		if (p.getName().compareTo( name ) == 0)
		{
		    return p;
		}
	    }
	}

	return null; //or throw an exception, as you like...
    }
	
    public InfoLong	findInfoLong( String name )
    {
	//find a publication which matches name and subscribe
	ListIterator	i = getPublications().listIterator();
	for(;i.hasNext();)
	{
	    Info	 p = (Info) i.next();

	    if (p.getName()!=null)
	    {
		if (p.getName().compareTo( name ) == 0)
		{
		    return (InfoLong)p;
		}
	    }
	}

	return null; //or throw an exception, as you like...
    }
}


